package Com.javaserver.servlet;

import Com.javaserver.bean.rewland;
import Com.javaserver.bean.staff;
import Com.javaserver.dao.staffserver;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;



//添加员工的接口
@WebServlet("/staffserver")
public class staffaddserverlet extends HttpServlet {
    staffserver sta = new staffserver();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String sid = req.getParameter("id");//员工编号
        String sname = req.getParameter("name");
        String sage = req.getParameter("age");
        String ssex = req.getParameter("sex");
        if (ssex.equals("1")){
            ssex="男";
        }else {
            ssex="女";
        }
        String sbirth = req.getParameter("birth");
        String scode = req.getParameter("code");
        String snation = req.getParameter("nation");
        String smarital = req.getParameter("marital");
        if (smarital.equals("1")){
            smarital="未婚";
        }else {
            smarital="已婚";
        }
        String spolitical = req.getParameter("political");
        if (spolitical.equals("2")){
            spolitical="党员";
        }else if (spolitical.equals("1")){
            spolitical="团员";
        }else {
            spolitical="无";
        }
        String snative = req.getParameter("native");
        String sphone = req.getParameter("phone");
        String shome = req.getParameter("home");
        String sshool = req.getParameter("shool");
        String smajor = req.getParameter("major");
        String seducation = req.getParameter("education");
        if (seducation.equals("1")){
            seducation="本科生";
        }else {
            seducation="研究生";
        }
        String stime = req.getParameter("time");
        String sdepartment_id = req.getParameter("department_id");
        String swork = req.getParameter("work");
        String spersons = req.getParameter("persons");
        String sduty = req.getParameter("duty");
        String sremarks = req.getParameter("remarks");
        staff s = new staff();
        s.setA_id(sid);
        s.setA_name(sname);
        s.setA_age(sage);
        s.setA_sex(ssex);
        s.setA_birth(sbirth);
        s.setA_code(scode);
        s.setA_nation(snation);
        s.setA_marital(smarital);
        s.setA_political(spolitical);
        s.setA_native(snative);
        s.setA_telephone(sphone);
        s.setA_home(shome);
        s.setA_school(sshool);
        s.setA_major(smajor);
        s.setA_education(seducation);
        s.setA_time(stime);
        s.setA_departmen_id(sdepartment_id);
        s.setA_work(swork);
        s.setA_persons(spersons);
        s.setA_duty(sduty);
        s.setA_remarks(sremarks);
//        s.setA_id(req.getParameter("id"));
//        s.setA_name(req.getParameter("name"));
//        s.setA_age(req.getParameter("age"));
//        s.setA_sex(req.getParameter("sex"));
//        if (){
//
//        }
//        s.setA_birth(req.getParameter("birth"));
//        s.setA_code(req.getParameter("code"));
//        s.setA_nation(req.getParameter("nation"));
//        s.setA_marital(req.getParameter("marital"));
//        s.setA_political(req.getParameter("political"));
//        s.setA_native(req.getParameter("native"));
//        s.setA_telephone(req.getParameter("phone"));
//        s.setA_home(req.getParameter("home"));
//        s.setA_school(req.getParameter("shool"));
//        s.setA_major(req.getParameter("major"));
//        s.setA_education(req.getParameter("education"));
//        s.setA_time(req.getParameter("time"));
//        s.setA_departmen_id(req.getParameter("department_id"));
//        s.setA_work(req.getParameter("work"));
//        s.setA_persons(req.getParameter("persons"));
//        s.setA_duty(req.getParameter("duty"));
//        s.setA_remarks(req.getParameter("remarks"));
//
//        staffserver staffed = new staffserver();


        if (sta.staAdd(s) == null) {
            req.getSession().setAttribute("msg", "添加失败");
            resp.sendRedirect(req.getContextPath() + "/StaffManagement.jsp");
        } else {

            List<staff> list = sta.stalist(1);
            req.getSession().setAttribute("staflist", list);
            req.getSession().setAttribute("nav", "员工查询");
            req.getSession().setAttribute("msg", "添加成功");
            resp.sendRedirect(req.getContextPath() + "/stalist");
        }
    }
}
